// 字符串首字母大写
const capitalize = str => str.charAt(0).toUpperCase() + str.slice(1)
console.log(capitalize('hello world'))

// 随机字符串
const randomString = () => Math.random().toString(36).slice(2)
console.log(randomString())

// 翻转字符串
const reverseString = str => str.split('').reverse().join('')
console.log(reverseString('hello world'))

// 截断字符串
const truncateString = (str, len) => str.length < len ? str : `${str.slice(0, len - 3)}...`
console.log(truncateString('dsagyuhfnskdnfhui huiasndfbhsbfnjkn', 10))

// 去除字符串中的HTML
const stripHtml = html => (new DOMParser().parseFromString(html, 'text/html')).body.textContent || ''
console.log(stripHtml('<p>海底隧道<span>hsajndj能否接受女方家</span></p><br /><img src="" width="200" />'))